package com.wt.util;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

import org.apache.commons.codec.binary.Base64;





public class MessageUtil {
	public static String md5(String msg){
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			byte[] input = msg.getBytes();
			byte[] output =md.digest(input);
			String ret_msg = Base64.encodeBase64String(output);
			
			return ret_msg;
			
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public static String createToken(){
		UUID uuid = UUID.randomUUID();
		return uuid.toString().replaceAll("-","");
	}
	
	public static String createId(){
		UUID uuid = UUID.randomUUID();
		return uuid.toString();
	}
	
	public static String base64Decode(String base64String){
		try{
			byte[] output = Base64.decodeBase64(base64String);
			return new String(output,"UTF-8");
		}catch(Exception ex){
			ex.printStackTrace();
			return null;
		}
	}
	
	public static void main(String[] args) {
		System.out.println(md5("123456"));
		System.out.println(createToken());
	}
	

}
